﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SIMS_GUI_Item
{
    public partial class ModificationPassWord : Form
    {
        public ModificationPassWord()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 传递参数
        /// </summary>
        /// <param name="UserName">帐号</param>
        /// <param name="PassWord">密码</param>
        public ModificationPassWord(string UserName,string PassWord)
        {
            InitializeComponent();
            txt_Account.Text = UserName;
            txt_OldPassWord.Text = PassWord;
        }

        /// <summary>
        /// 默认选中帐号文本框
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ModificationPassWord_Load(object sender, EventArgs e)
        {
            this.txt_Account.Focus();
        }

        /// <summary>
        /// 点击按钮
        /// </summary>
        SIMS_GUI_Item_DataBase db = new SIMS_GUI_Item_DataBase();
        Login lg = new Login();
        private void btn_Confirm_Click(object sender, EventArgs e)
        {
            string Account = this.txt_Account.Text;
            string OldPassWord = this.txt_OldPassWord.Text;
            string NewPassWord = this.txt_NewPassWord.Text;
            var sql = string.Format("update UserInformation set PassWord='{0}'", NewPassWord);
            CheckNull(NewPassWord);
            int number = Convert.ToInt32(db.ExecNonQuery(sql));
            if (number > 0)
            {
                MessageBox.Show("修改成功");
                this.Hide();
            }
            else
            {
                MessageBox.Show("修改失败");
            }
        }

        //判断UserName和PassWord是否为空
        public bool CheckNull(string NewPassWord)
        {
            if (string.IsNullOrWhiteSpace(NewPassWord))
            {
                DialogResult dr = MessageBox.Show("请输入密码", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                this.txt_NewPassWord.Focus();
                return true;
            }
            return false;
        }
    }
}
